/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class TESTArinsoWebServices {

    static testMethod void myUnitTest() { 
        
        //Getting the initial count of survey objects
        List <Customer_Satisfaction_Survey__c> initCount = [Select c.Id From Customer_Satisfaction_Survey__c c];
        
        //Setup data set - Add Account and contact
        Account account = new Account();
        account.Name = 'TestAccount';
        account.Industry = 'Education';
        account.Employees_Local__c = 12;
        account.Type = 'Customer';
        account.CurrencyIsoCode = 'EUR';
        account.Phone = '+94222222';
		account.BillingCity = 'Brussels';
		account.BillingCountry = 'Belgium';        
        insert account;
        
        account = [Select a.Id From Account a where a.Name = :'TestAccount' limit 1];
        
        Contact contact = new Contact();
        contact.AccountId = account.Id;
        contact.Email = 'malaka@absi.be';
        contact.FirstName = 'First Name';
        contact.LastName = 'Last Name';
        contact.Survey_registered__c = true;
        insert contact;
        
        contact = [Select c.Id From Contact c where c.FirstName = :'First Name' limit 1];
   
        String strContactId = contact.Id;   
   
       //Test add response web service with various tes values
       ArinsoWebServices.addSurveyResponse(null, '2009', '01', 3, 3, 3, 3, 3, '3', 3, 3, '3', 'yes','comment','yes','no','yes','comment');
       ArinsoWebServices.addSurveyResponse(strContactId, null, '01', 3, 3, 3, 3, 3, '3', 3, 3, '3', 'yes','comment','yes','no','yes','comment'); 
       ArinsoWebServices.addSurveyResponse(strContactId, '2009', null, 3, 3, 3, 3, 3, '3', 3, 3, '3', 'yes','comment','yes','no','yes','comment');   
       ArinsoWebServices.addSurveyResponse('003S00000045681', '2009', '11', 1, 1, 2, 2, 3, '3', 4, 4, '5', 'yes','comment', 'yes', 'yes', 'no','comment');     
       ArinsoWebServices.addSurveyResponse(strContactId, '2009', '11', 3, 3, 3, 3, 3, '3', 3, 3, '3', 'yes','comment','yes','no','yes','comment');           
       ArinsoWebServices.addSurveyResponse(strContactId, '2009', '11', 1, 1, 2, 2, 3, '3', 4, 4, '5', 'yes','comment','yes', 'yes', 'no','comment');
       ArinsoWebServices.addSurveyResponse(strContactId, '2009', '12', 1, 1, 1, 1, 1, '1', 1, 1, '1', 'yes','comment','yes','no','yes','comment');
       
       //Test get response with various values
       ArinsoWebServices.getSurveyResponse(strContactId, '2009', '12');
       ArinsoWebServices.getSurveyResponse(strContactId, '2009', '01');
       ArinsoWebServices.getSurveyResponse('003S00000056gt6', '2009', '01');
       ArinsoWebServices.getSurveyResponse(null, '2009', '01');
       ArinsoWebServices.getSurveyResponse(strContactId, '09', '01');
       ArinsoWebServices.getSurveyResponse(strContactId, null, '01');
       ArinsoWebServices.getSurveyResponse(strContactId, '2009', null);
       ArinsoWebServices.getSurveyResponse(strContactId, null, null);
       
       //Test VCM Responses Duplicate
       Customer_Satisfaction_Survey__c newSurvey = new Customer_Satisfaction_Survey__c();
	
	   newSurvey.Contact__c = strContactId;
	  
	   newSurvey.VCMresponse1__c = 2;
	   newSurvey.VCMresponse2__c = 2;       
	   newSurvey.VCMresponse3__c = 2;
	   newSurvey.VCMresponse4__c = 2;
	   newSurvey.VCMresponse5__c = 2;
	   newSurvey.VCMresponse6__c = '2';
	   newSurvey.VCMresponse7__c = 2;
	   newSurvey.VCMresponse8__c = 2;
	   newSurvey.VCMresponse9__c = '2';
	   newSurvey.VCMresponse_10__c = 'Yes';
	   newSurvey.VCMresponse_11__c = 'yes';
	   newSurvey.VCMresponse_12__c = 'no';
	   newSurvey.VCMResponse_13__c = 'no';
	   newSurvey.VCMResponse_14__c = 'comment';
	   newSurvey.Survey_Month__c = '01';
	   newSurvey.Survey_Year__c = '2009';
	   Database.insert(newSurvey);
       
       //Test Customer responses
       try{
           newSurvey = new Customer_Satisfaction_Survey__c();
           newSurvey.Contact__c = strContactId;
           
           newSurvey.CustomerResponse1__c = 6;
           newSurvey.CustomerResponse2__c = 6;
           newSurvey.CustomerResponse3__c = 6;
           newSurvey.CustomerResponse4__c = 6;
           newSurvey.CustomerResponse5__c = 6;
           newSurvey.CustomerResponse6__c = '6';
           newSurvey.CustomerResponse7__c = 6;
           newSurvey.CustomerResponse8__c = 6;
           newSurvey.CustomerResponse9__c = '6';
           newSurvey.CustomerResponse10__c = 'Yes';
           newSurvey.Customerresponse11__c = 'yes';
           newSurvey.Customerresponse12__c = 'no';
           newSurvey.Customerresponse14__c = 'comment';
             
           newSurvey.Survey_Month__c = '12';
           newSurvey.Survey_Year__c = '2009';
           Database.insert(newSurvey);      
           system.assert(false);
       }catch(Exception e){
            system.assert(true);
       } 

		
	   try{
	       newSurvey = new Customer_Satisfaction_Survey__c();
	       newSurvey.Contact__c = strContactId;
	       
	       newSurvey.CustomerResponse1__c = 7;
	       newSurvey.CustomerResponse2__c = 1;
	       newSurvey.CustomerResponse3__c = 1;
	       newSurvey.CustomerResponse4__c = 7;
	       newSurvey.CustomerResponse5__c = 1;
	       newSurvey.CustomerResponse6__c = '1';
	       newSurvey.CustomerResponse7__c = 1;
	       newSurvey.CustomerResponse8__c = 1;
	       newSurvey.CustomerResponse9__c = '7';
	       newSurvey.CustomerResponse10__c = 'Yes';
	       newSurvey.Customerresponse11__c = 'yes';
	       newSurvey.Customerresponse12__c = 'no';
	       newSurvey.Customerresponse13__c = 'no';
	       newSurvey.Customerresponse13__c = 'comment';
	  
	       newSurvey.Survey_Month__c = '02';
	       newSurvey.Survey_Year__c = '2009';
	       Database.insert(newSurvey);
           system.assert(false);
       }catch(Exception e){
            system.assert(true);	       
	   }
	   
       newSurvey = new Customer_Satisfaction_Survey__c();
       newSurvey.Contact__c = strContactId;
       
       newSurvey.VCMresponse1__c = 3;
       newSurvey.VCMresponse2__c = 3;
       newSurvey.VCMresponse3__c = 3;
       newSurvey.VCMresponse4__c = 3;
       newSurvey.VCMresponse5__c = 3;
       newSurvey.VCMresponse6__c = '3';
       newSurvey.VCMresponse7__c = 3;
       newSurvey.VCMresponse8__c = 3;
       newSurvey.VCMresponse9__c = '3';
       newSurvey.VCMresponse_10__c = 'Yes';
       newSurvey.VCMresponse_11__c = 'yes';
       newSurvey.VCMresponse_12__c = 'no';
       newSurvey.VCMresponse_13__c = 'no';
       newSurvey.VCMresponse_14__c = 'comment';
         
       newSurvey.Survey_Month__c = '06';
       newSurvey.Survey_Year__c = '2009';
       Database.insert(newSurvey);

	   ArinsoWebServices.addSurveyResponse(strContactId, '2009', '06', 1, 1, 1, 1, 1, '1', 1, 1, '1', 'yes','comment','yes','no','yes','comment');

       List <Customer_Satisfaction_Survey__c> endCount = [Select c.Id From Customer_Satisfaction_Survey__c c];
       
       system.assert((initCount.size() + 4) == endCount.size());
       //system.assertEquals(initCount.size(), (endCount.size() - 2));
    }
}